
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.FileInputStream;
import javax.swing.JLabel;
import javax.swing.JPanel;
import sun.audio.AudioData;
import sun.audio.AudioDataStream;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Henri
 */
public class sliepka_kuk extends JLabel implements Runnable, MouseListener {

//    Timer t;
    Thread th = new Thread(this);
    JPanel jp;
    skore s;
    Hra h = new Hra();
    boolean existuje;

        public void killed(){
        AudioPlayer ap = AudioPlayer.player;
        AudioStream as;
        AudioData ad;
        AudioDataStream zvuk = null;
        try {
            ;
            as = new AudioStream(new FileInputStream("zvuky/killChicken.wav"));
            ad = as.getData();
            zvuk = new AudioDataStream(ad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ap.start(zvuk);
    
    }
    public sliepka_kuk(JPanel j) {
        th.start();
        existuje = true;
        this.jp = j;
        setBounds(900, 404, 75, 96);
        addMouseListener(this);
        this.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/moorhuhnKuk.gif")));
    }

    public void zmiznutie() {
        jp.remove(this);
        jp.repaint();
    }

    @Override
    public void run() {
        try {
            th.sleep(1700);
            zmiznutie();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public void mouseClicked(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
        if (e.getButton() == e.BUTTON1 && h.strely >= 2) {
            zmiznutie();
            s = new skore(this.getX(), this.getY(), jp);
                jp.add(s);
                killed();
                h.skore += 70;
        }
        if (e.getButton() == e.BUTTON3 && h.strely <= 1) {
            h.nabi();
        }
        h.mousePressed(e);
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }
}
